import request from '/@/utils/http/axios';
import { LoginParams, refreshTokenParams, GetUserInfoModel } from '/@/model/user/userModel';

/**
 *  @description 登录
 */

export const login = (params: LoginParams) => {
  const { key, code, tenantId, password, username } = params;
  return request.post({
    url: '/api/paas-auth/oauth/token',
    params: {
      password,
      username,
      tenantId,
      grant_type: 'captcha',
      scope: 'all',
      type: 'account'
    },
    headers: {
      'Tenant-Id': String(tenantId),
      'Captcha-Key': key,
      'Captcha-Code': code
    }
  });
};

/**
 *  @description 刷新验证码
 */
export const getCaptcha = () => {
  return request.get({ url: '/api/paas-auth/oauth/captcha' });
};

/**
 *  @description 刷新token
 */
export const refreshToken = (params: refreshTokenParams) => {
  return request.post({ url: '/api/paas-auth/oauth/token', params });
};

/**
 * @description: 获取用户信息
 */
export function getUserInfo() {
  return request.get<GetUserInfoModel>({ url: '' });
}
